/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*                                                                  *
*        *************************************************         *
*        *©2021-2027 HT Corporation All rights reserved *          *
*        *************************************************         *
*                                                                  *
* FileName    : h_register.c                                       *
*                                                                  *
* Author      : linus                                              *
*                                                                  *
* Email       : luoyaojun@haitutech.com                           *
*                                                                  *
* Date        : 2022-8-8                                           *
*                                                                  *
* Description :                                                    *
*                                                                  *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
//#include "ht_mpp.h"
#include "h_comm.h"
#include "h_register.h"

struct ht_modules g_modules[HT_ID_BUTT];

static int ht_registed_check_id(HT_MOD_ID id)
{
	if ( id <0 || id >=HT_ID_BUTT)
		return -1;

	return 0;
}

static struct ht_modules *
	ht_registed_get(HT_MOD_ID id)
{
	if (ht_registed_check_id(id))
		return NULL;

	return &g_modules[id];
}

HT_S32 ht_register_modules(HT_MOD_ID id, HT_HANDLE priv)
{
	if (!priv)
		return -1;

	if (ht_registed_check_id(id))
		return -2;

	g_modules[id].module_id = id;
	g_modules[id].module_priv = priv;

	return 0;
}

HT_VOID ht_registed_set_suffix(HT_MOD_ID id, const char *suffix)
{
	struct ht_modules *pmodules = ht_registed_get(id);

	if (pmodules)
		pmodules->suffix = suffix;
}

HT_VOID ht_registed_set_config(HT_MOD_ID id, HT_HANDLE config)
{
	struct ht_modules *pmodules = ht_registed_get(id);

	if (pmodules)
		pmodules->config = config;
}
